 $(document).ready(function() {
      $( "#accordion" ).accordion({collapsible:true, autoHeight:false});
      $( "#dialogWishToSave").dialog({ autoOpen: false, resizable:false, modal:true }); 
      $( "button" ).button();
      $( "#homeButton" ).click(function() { 		
            $( "#dialogWishToSave" ).dialog('open'); return false; 
      });
      $( "#runButton" ).click(function () {  
           compiler = compiler._runCompiler(editor.getSession().getValue());
           window.alert(compiler);    
      }); 
 
      $( "#saveButton" ).click(function () {  
                var content = JSON.encode(editor.getSession().getValue()); 
                $.ajax({ 
                    type:"POST", 
                    url:"includes/php/docajax.php", 
                    data:"action=save&content="+content+"&doc_id=<?php echo $doc_id;?>",
                    success: function(xhr){  
                        if (xhr) 
                        {
                            //TODO add in Saving, Saved thing in top right 
                            $("span.timeago").html(jQuery.timeago(xhr));  
                            $("span.timeago").attr("title", xhr);
                        }
                    }
            }); 
        }); 
    $("#dialogWishToSave").dialog('option', 'buttons', {  
            "Yes" : function() { 
                var content = JSON.encode(editor.getSession().getValue()); 
                $.ajax({
                    type:"POST", 
                    url:"includes/php/docajax.php", 
                    data:"action=save&content="+content+"&doc_id=<?php echo $doc_id;?>",
                    success: function(xhr){ 
                        window.location.href = '/indstudy/index.php';  
                    } 
                }); 
            },
            "No" : function() { 
                window.location.href = '/indstudy/index.php';  
            },
            "Cancel" : function() {
                $(this).dialog("close"); 
            },
     });
 
 }); 
